package com.ruoyi.web.controller.house;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.WebmagicBuilding;
import com.ruoyi.house.service.IWebmagicBuildingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼宇Controller
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Controller
@RequestMapping("/house/building")
public class WebmagicBuildingController extends BaseController
{
    private String prefix = "house/building";

    @Autowired
    private IWebmagicBuildingService webmagicBuildingService;

    @RequiresPermissions("house:building:view")
    @GetMapping()
    public String building()
    {
        return prefix + "/building";
    }

    /**
     * 查询楼宇列表
     */
    @RequiresPermissions("house:building:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebmagicBuilding webmagicBuilding)
    {
        startPage();
        List<WebmagicBuilding> list = webmagicBuildingService.selectWebmagicBuildingList(webmagicBuilding);
        return getDataTable(list);
    }

    /**
     * 导出楼宇列表
     */
    @RequiresPermissions("house:building:export")
    @Log(title = "楼宇", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebmagicBuilding webmagicBuilding)
    {
        List<WebmagicBuilding> list = webmagicBuildingService.selectWebmagicBuildingList(webmagicBuilding);
        ExcelUtil<WebmagicBuilding> util = new ExcelUtil<WebmagicBuilding>(WebmagicBuilding.class);
        return util.exportExcel(list, "楼宇数据");
    }

    /**
     * 新增楼宇
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存楼宇
     */
    @RequiresPermissions("house:building:add")
    @Log(title = "楼宇", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebmagicBuilding webmagicBuilding)
    {
        return toAjax(webmagicBuildingService.insertWebmagicBuilding(webmagicBuilding));
    }

    /**
     * 修改楼宇
     */
    @RequiresPermissions("house:building:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebmagicBuilding webmagicBuilding = webmagicBuildingService.selectWebmagicBuildingById(id);
        mmap.put("webmagicBuilding", webmagicBuilding);
        return prefix + "/edit";
    }

    /**
     * 修改保存楼宇
     */
    @RequiresPermissions("house:building:edit")
    @Log(title = "楼宇", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebmagicBuilding webmagicBuilding)
    {
        return toAjax(webmagicBuildingService.updateWebmagicBuilding(webmagicBuilding));
    }

    /**
     * 删除楼宇
     */
    @RequiresPermissions("house:building:remove")
    @Log(title = "楼宇", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webmagicBuildingService.deleteWebmagicBuildingByIds(ids));
    }
}
